//
//  LLT_VideoDetailTableViewCell_LXH.m
//  CoderLLT
//
//  Created by lanou3g on 15/12/15.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "LLT_VideoDetailTableViewCell_LXH.h"
#import "UIImageView+WebCache.h"
#import "LLT_VideoModel.h"

@interface LLT_VideoDetailTableViewCell_LXH()

@property (weak, nonatomic) IBOutlet UIImageView *videoImageView;

@property (weak, nonatomic) IBOutlet UILabel *videoTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *videoCreateLabel;
@property (weak, nonatomic) IBOutlet UIImageView *personImageView;

@property (weak, nonatomic) IBOutlet UILabel *personNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *personCountLabel;

@end


@implementation LLT_VideoDetailTableViewCell_LXH

-(void)setVideoModel:(LLT_VideoModel *)videoModel{
    
    if (_videoModel != videoModel) {
        _videoModel = nil;
        _videoModel = videoModel;
    }
    [self setCell];
}
/**
 * 设置横竖屏
 */


-(BOOL)shouldAutorotate {
    return YES;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

/**
 * 设置cell
 */
-(void)setCell{
    
    [self.videoImageView sd_setImageWithURL:[NSURL URLWithString:self.videoModel.thumb_img]placeholderImage:[UIImage imageNamed:@"placeHolder"]];
    
    self.videoTitleLabel.text = [NSString stringWithFormat:@"%@",self.videoModel.title];
    //调用方法计算出时间
    self.videoCreateLabel.text = [self getNewsDateLabelTextByString:self.videoModel.create_time];
    //self.videoCreateLabel.text = [NSString stringWithFormat:@"%@",self.videoModel.create_time];
    
    [self.personImageView sd_setImageWithURL:[NSURL URLWithString:self.videoModel.avatar]placeholderImage:[UIImage imageNamed:@"mhead"]];
    
    self.personCountLabel.text = [NSString stringWithFormat:@"%@",self.videoModel.play_times];
    
    self.personNameLabel.text = [NSString stringWithFormat:@"%@",self.videoModel.username];
}


/**
 * 计算时间的方法
 */
-(NSString *)getNewsDateLabelTextByString:(NSString *)string{
    
    long long int date1 = (long long int) [string intValue];
    NSDate *currentDate = [NSDate date];
    NSTimeInterval currentInterval = [currentDate timeIntervalSince1970];
    NSMutableString *s = [NSMutableString string];
    
    NSTimeInterval interval = date1 - currentInterval;
    
    if (interval > -1 * 60 *60) {
        NSInteger count = interval / 60;
        s = [NSMutableString stringWithFormat:@"🕘 %ld分钟前",-count];
    }else if(interval > - 24 * 60 * 60) {
        NSInteger count = interval / (60 * 60);
        s = [NSMutableString stringWithFormat:@"🕘 %ld小时前",-count];
    }else if (interval > - 30 * 24 * 60 * 60){
        NSInteger count = interval / (24 * 60 * 60);
        s = [NSMutableString stringWithFormat:@"🕘 %ld天前",-count];
    }else{
        NSInteger count = interval / (24 * 60 * 60);
        s = [NSMutableString stringWithFormat:@"🕘 %ld天前",-count];
    }
    return s;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



@end
